<template>
  <div class="dashboard_container">
    <div class="card-title">设备异常</div>
    <div class="card-main">
      <div>设备正常率</div>
      <div>
        {{
          deviceData.onlineNumber == 0
            ? 0
            : (
                (deviceData.normalNumber / deviceData.onlineNumber) *
                100
              ).toFixed(0)
        }}%
      </div>
    </div>
    <div class="card-foot">
      <div class="line">
        <div>在线总数</div>
        <div>{{ deviceData.onlineNumber }}</div>
      </div>
      <div class="line">
        <div>正常</div>
        <div>{{ deviceData.normalNumber }}</div>
      </div>
      <div>
        <div>告警</div>
        <div
          class="jump_dom"
          v-if="deviceData.alarmNumber > 0"
          @click="jumpPage"
        >
          {{ deviceData.alarmNumber }}
          <img src="@/assets/images/jump_icon.png" alt="" />
        </div>
        <div v-else>{{ deviceData.alarmNumber }}</div>
      </div>
    </div>
    <div class="ball">
      <span>
        {{
          deviceData.onlineNumber == 0
            ? 0
            : (
                (deviceData.normalNumber / deviceData.onlineNumber) *
                100
              ).toFixed(0)
        }}%</span
      >
    </div>
  </div>
</template>

<script setup lang="tsx">
import { ref } from 'vue';
import router from '@/router';

const jumpPage = () => {
  router.push({
    path: 'audit/log/warnLogs',
    query: { onlineStatus: '1', handleState: '0' },
  });
};
const props = defineProps({
  deviceData: {
    type: Object,
    default: () => {},
  },
});
</script>

<style lang="scss" scoped>
@use '../style.scss';
.dashboard_container {
  background-image: url('@/assets/images/abnormal-bg.png');
}
</style>
